
package kaizen.com;

import java.io.*;

public final class Log
{

  public static void enableAll(boolean flag)
  {
    enableApp(flag);
    enableErr(flag);
    enableSql(flag);
  }

  public static void enableApp(boolean flag)
  {
    lb_app_enabled = flag;
  }

  public static void enableErr(boolean flag)
  {
    lb_err_enabled = flag;
  }

  public static void enableSql(boolean flag)
  {
    lb_sql_enabled = flag;
  }

  public static void setAllFiles(String s, String s1, String s2)
  {
    setAppFile(s);
    setErrFile(s);
    setSqlFile(s);
  }

  public static void setAppFile(String s)
  {
    ls_app_file = s;
  }

  public static void setErrFile(String s)
  {
    ls_err_file = s;
  }

  public static void setSqlFile(String s)
  {
    ls_sql_file = s;
  }

  public static void openAll()
  {
    openApp();
    openErr();
    openSql();
  }

  public static boolean openApp()
  {
    if (lb_app_enabled && !lb_app_file_opened)
    {
      try
      {
        lraf_app = new RandomAccessFile(ls_app_file, "rw");
        lb_app_file_opened = true;
      } catch (IOException _ex)
      {
        System.out.println("Error al abrir el log de la aplicaci\363n : " + 
                           ls_app_file);
      }
      return lb_app_file_opened;
    } else
    {
      return false;
    }
  }

  public static boolean openErr()
  {
    if (lb_err_enabled && !lb_err_file_opened)
    {
      try
      {
        lraf_err = new RandomAccessFile(ls_err_file, "rw");
        lb_err_file_opened = true;
      } catch (IOException _ex)
      {
        System.out.println("Error al abrir el log de errores : " + 
                           ls_err_file);
      }
      return lb_err_file_opened;
    } else
    {
      return false;
    }
  }

  public static boolean openSql()
  {
    if (lb_sql_enabled && !lb_sql_file_opened)
    {
      try
      {
        lraf_sql = new RandomAccessFile(ls_sql_file, "rw");
        lb_sql_file_opened = true;
      } catch (IOException _ex)
      {
        System.out.println("Error al abrir el log de sql : " + ls_sql_file);
      }
      return lb_sql_file_opened;
    } else
    {
      return false;
    }
  }

  public static void closeAll()
  {
    closeApp();
    closeErr();
    closeSql();
  }

  public static void closeApp()
  {
    if (lb_app_file_opened)
    {
      try
      {
        lraf_app.close();
      } catch (IOException _ex)
      {
        System.out.println("Error al cerrar el archivo del log de la aplicaci\363n : " + 
                           ls_app_file);
      }
      lb_app_file_opened = false;
    }
  }

  public static void closeErr()
  {
    if (lb_err_file_opened)
    {
      try
      {
        lraf_err.close();
      } catch (IOException _ex)
      {
        System.out.println("Error al cerrar el archivo del log de errores : " + 
                           ls_err_file);
      }
      lb_err_file_opened = false;
    }
  }

  public static void closeSql()
  {
    if (lb_sql_file_opened)
    {
      try
      {
        lraf_sql.close();
      } catch (IOException _ex)
      {
        System.out.println("Error al cerrar el archivo del log de sql : " + 
                           ls_sql_file);
      }
      lb_sql_file_opened = false;
    }
  }

  public static void writeErr(String s)
  {
    if (lb_err_enabled && lb_err_file_opened)
    {
      try
      {
        lraf_err.writeBytes(s);
        lraf_err.writeBytes(ls_newline);
        return;
      } catch (IOException _ex)
      {
        System.out.println("Error al escribir en el log de errores");
      }
      return;
    } else
    {
      return;
    }
  }

  public static void writeApp(String s)
  {
    if (lb_app_enabled && lb_app_file_opened)
    {
      try
      {
        lraf_app.writeBytes(s);
        lraf_app.writeBytes(ls_newline);
        return;
      } catch (IOException _ex)
      {
        System.out.println("Error al escribir en el log de la aplicaci\363n");
      }
      return;
    } else
    {
      return;
    }
  }

  public static void writeSql(String s)
  {
    if (lb_sql_enabled && lb_sql_file_opened)
    {
      try
      {
        lraf_sql.writeBytes(s);
        lraf_sql.writeBytes(ls_newline);
        return;
      } catch (IOException _ex)
      {
        System.out.println("Error al escribir en el log de sql");
      }
      return;
    } else
    {
      return;
    }
  }

  public Log()
  {
  }

  private static boolean lb_err_enabled;
  private static boolean lb_app_enabled;
  private static boolean lb_sql_enabled;
  private static boolean lb_err_file_opened;
  private static boolean lb_app_file_opened;
  private static boolean lb_sql_file_opened;
  private static String ls_err_file = "";
  private static String ls_app_file = "";
  private static String ls_sql_file = "";
  private static RandomAccessFile lraf_app;
  private static RandomAccessFile lraf_err;
  private static RandomAccessFile lraf_sql;
  private static String ls_newline = "\n";

}
